Vue.component('Add', {
	template: `
		<el-dialog title="添加" width="600px" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<el-form :size="size" ref="form" :model="form" :rules="rules" :label-width=" ismobile()?'90px':'16%'">
				<el-row >
					<el-col :span="24">
						<el-form-item label="订单编号" prop="order_num">
							<el-input  v-model="form.order_num" autoComplete="off" clearable  placeholder="请输入订单编号"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="订单类型" prop="order_type">
							<el-select style="width:100%" v-model="form.order_type" filterable clearable placeholder="请选择订单类型">
								<el-option key="0" label="家长需求" :value="1"></el-option>
								<el-option key="1" label="老师兼职" :value="2"></el-option>
								<el-option key="2" label="直接购买" :value="3"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="对象ID" prop="order_obj_id">
							<el-input  v-model="form.order_obj_id" autoComplete="off" clearable  placeholder="请输入对象ID"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="家长ID" prop="parent_id">
							<el-input  v-model="form.parent_id" autoComplete="off" clearable  placeholder="请输入家长ID"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="老师ID" prop="teacher_id">
							<el-input  v-model="form.teacher_id" autoComplete="off" clearable  placeholder="请输入老师ID"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="课时单价" prop="class_fee">
							<el-input-number controls-position="right" style="width:200px;" autoComplete="off" v-model="form.class_fee" clearable :min="0" placeholder="请输入课时单价"/>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="课时数量" prop="class_num">
							<el-input  v-model="form.class_num" autoComplete="off" clearable  placeholder="请输入课时数量"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="课时时长" prop="class_hour">
							<el-input  v-model="form.class_hour" autoComplete="off" clearable  placeholder="请输入课时时长"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">确 定</span>
					<span v-else>提 交 中...</span>
				</el-button>
				<el-button :size="size" @click="closeForm">取 消</el-button>
			</div>
		</el-dialog>
	`
	,
	components:{
	},
	props: {
		show: {
			type: Boolean,
			default: false
		},
		size: {
			type: String,
			default: 'small'
		},
	},
	data(){
		return {
			form: {
				order_num:'',
				order_type:1,
				order_obj_id:'',
				parent_id:'',
				teacher_id:'',
				class_num:1,
				class_hour:'',
				create_time:'',
			},
			loading:false,
			rules: {
				order_num:[
					{required: true, message: '订单编号不能为空', trigger: 'blur'},
				],
				order_type:[
					{required: true, message: '订单类型不能为空', trigger: 'change'},
				],
				parent_id:[
					{required: true, message: '家长ID不能为空', trigger: 'blur'},
				],
				teacher_id:[
					{required: true, message: '老师ID不能为空', trigger: 'blur'},
				],
				class_fee:[
					{required: true, message: '课时单价不能为空', trigger: 'blur'},
				],
				class_num:[
					{required: true, message: '课时数量不能为空', trigger: 'blur'},
					{pattern:/^[0-9]*$/, message: '课时数量格式错误'}
				],
				class_hour:[
					{required: true, message: '课时时长不能为空', trigger: 'blur'},
					{pattern:/^[0-9]*$/, message: '课时时长格式错误'}
				],
			}
		}
	},
	methods: {
		open(){
		},
		submit(){
			this.$refs['form'].validate(valid => {
				if(valid) {
					this.loading = true
					axios.post(base_url + '/Order.Order/add',this.form).then(res => {
						if(res.data.status == 200){
							this.$message({message: res.data.msg, type: 'success'})
							this.$emit('refesh_list')
							this.closeForm()
						}else{
							this.loading = false
							this.$message.error(res.data.msg)
						}
					}).catch(()=>{
						this.loading = false
					})
				}
			})
		},
		closeForm(){
			this.$emit('update:show', false)
			this.loading = false
			if (this.$refs['form']!==undefined) {
				this.$refs['form'].resetFields()
			}
		},
	}
})
